package com.Daisy.swi.client.Data;

import java.io.Serializable;
import java.util.ArrayList;

public class ReaderList implements Serializable{
	private static final long serialVersionUID = 5011362280545665640L;
	private ArrayList<Reader> readers=new ArrayList<Reader>();
	
	public void add(Reader r){
		readers.add(r);
	}
	
	public void remove(Reader r){
		readers.remove(r);
	}
	
	public Reader get(int i){
		return readers.get(i);
	}
	
	public Reader get(String id){
		for (int i=0;i<readers.size();i++){
			if (readers.get(i).getID().equals(id)){
				return readers.get(i);
			}
		}
		return null;
	}
	
	public int size(){
		return readers.size();
	}

	public void remove(int i){
		readers.remove(i);
	}
	
	public boolean check(String id,String password){
		for (int i=0;i<this.size();i++){
			Reader r=this.get(i);
			if (r.getID().equals(id) && r.getPassword().equals(password)){
				return true;
			}
		}
		return false;
	}
	
	public boolean resetReader(String name, String newID, String id, 
			String password, String institute, int type){
		boolean isLegal=true;
		
		if (!newID.equals(id)){
			for (int i=0;i<this.size();i++){
				Reader r=this.get(i);
				if (r.getID().equals(newID)){
					isLegal=false;	
					break;
				}
			}
		}	
		
		if (isLegal){
			Reader r=this.get(id);
			r.resetInformation(name, newID, password, institute, type);
		}
		return isLegal;
	}
	
}
